//验收信息
function fundAccps() {
    // 初验报告
    var recaColumns = [{
        id: 'contractId',
        title: '合同编号',
        width: 150,
        type: 'string',
        columnClass: 'text-center',
    }, {
        id: 'acceptanceType',
        title: '类型',
        width: 80,
        type: 'string',
        columnClass: 'text-center',
    }, {
        id: 'customerName',
        title: '验收签字人',
        width: 90,
        type: 'string',
        columnClass: 'text-center',
    }, {
        id: 'acceptanceTime',
        title: '验收日期',
        width: 120,
        type: 'date',
        format: 'yyyy-MM-dd',
        otype: 'time_stamp_ms',
        columnClass: 'text-center',
    }, {
        id: 'acceptanceResult',
        title: '验收结果',
        width: 100,
        type: 'string',
        columnClass: 'text-center'
    }, {
        id: 'acceptanceComments',
        title: '验收结果说明',
        // width: 150,
        type: 'string',
        columnClass: 'text-left',
    }, {
        id: 'operation',
        title: '操作',
        type: 'string',
        width: 70,
        columnClass: 'text-center',
        resolution: function (value, record, column, grid, dataNo, columnNo) {
            var content = '无';
            //计算相差多少天
            var d = new Date();
            start = formatTime(record.createTime).replace(/-/g, "/");
            var startdate = new Date(start);
            var time = d.getTime() - startdate.getTime();
            var days = parseInt(time / (1000 * 60 * 60 * 24));
            //大于三天则不能修改和删除
            if (days <= 1) {
                content = '<button class="btn btn-xs btn-danger" onclick="delaccp(' + record.id + ');"><i class="fa fa-trash-o"></i>  删除</button>';
            }
            // content += '<button class="btn btn-xs btn-success" onclick="reca(' + record.id + ');"><i class="icon-edit"></i>  编辑</button>';
            // content += '  ';
            // content += '<button class="btn btn-xs btn-info" onclick="downaccp(\'' + record.fileUrl + '\');"><i class="icon-cloud-download"></i>  下载</button>';
            // content += '  ';
            return content;
        }
    }];
    $certusUtils.ajax("findAccetpances", { "projId": proId }, function (response) {
        var recaOption = {
            lang: 'zh-cn',
            ajaxLoad: false,
            extraWidth: 20,
            // loadURL:'url',
            exportFileName: '合同文件列表',
            datas: response.data,
            columns: recaColumns,
            gridContainer: 'recaContainer',
            tools: ''
        };
        var recaGrid = $.fn.dlshouwen.grid.init(recaOption);
        recaGrid.load();
    })

    //已删除的验收信息
    var delColumns = [{
        id: 'contractId',
        title: '合同编号',
        width: 150,
        type: 'string',
        columnClass: 'text-center',
    }, {
        id: 'acceptanceType',
        title: '类型',
        width: 80,
        type: 'string',
        columnClass: 'text-center',
    }, {
        id: 'customerName',
        title: '验收签字人',
        width: 90,
        type: 'string',
        columnClass: 'text-center',
    }, {
        id: 'acceptanceTime',
        title: '验收日期',
        width: 120,
        type: 'date',
        format: 'yyyy-MM-dd',
        otype: 'time_stamp_ms',
        columnClass: 'text-center',
    }, {
        id: 'acceptanceResult',
        title: '验收结果',
        width: 100,
        type: 'string',
        columnClass: 'text-center'
    }, {
        id: 'delTime',
        title: '删除日期',
        width: 120,
        type: 'date',
        format: 'yyyy-MM-dd',
        otype: 'time_stamp_ms',
        columnClass: 'text-center',
    }, {
        id: 'delUserName',
        title: '删除人',
        width: 80,
        type: 'string',
        columnClass: 'text-center'
    }];
    $certusUtils.ajax("findProDelAcceps", { "proId": proId }, function (response) {
        var recaOption = {
            lang: 'zh-cn',
            ajaxLoad: false,
            extraWidth: 20,
            // loadURL:'url',
            exportFileName: '已删除验收记录',
            datas: response.data,
            columns: delColumns,
            gridContainer: 'recaDelContainer',
            tools: ''
        };
        var recaGrid = $.fn.dlshouwen.grid.init(recaOption);
        recaGrid.load();
    })
}

function formatTime(param) {
    var date = new Date(param);
    var content = $.fn.dlshouwen.grid.tools.dateFormat(date, "yyyy-MM-dd");
    return content;
}

function delaccp(id) {
    layer.confirm('确认删除此数据？', {
        btn: ['确认', '取消'] //按钮
    }, function () {
        $certusUtils.ajax("delAccps", { "id": id, "projId": proId }, function () {
            toLoadHtml(101);
        });
        layer.msg('删除成功');
    });
}
function downaccp(fileId) {
    $certusUtils.download("downAccpFile", "uploadFilePath=" + fileId);
}

function reca(id) {
    $("#rightContainer").empty();
    $$http({
        url: "proinfo/edit/edit-reca.html",
        method: 'GET',
        data: {},
        dataType: "application/json"
    }).then(function (a) {
        $$scope.htmlxx = a.data;
        $CertusFormAjax = $certusUtils;
    }, function (b) {
    })
}
function toAddAccps() {
    $("#rightContainer").empty();
    $$http({
        url: "proinfo/edit/add-reca.html",
        method: 'GET',
        data: {},
        dataType: "application/json"
    }).then(function (a) {
        $$scope.htmlxx = a.data;
        $CertusFormAjax = $certusUtils;
        addAccps();
    }, function (b) {
    });
}

$('#acceptanceTime').datepicker({
    format: 'yyyy-mm-dd'
});
//新增验收信息
function addAccps() {
    var fileInstantiation = {
        classCateCode: 'NBCPYZ',//选定市场类 文档
        fileClassCode: 'QT' //
    }
    var fileInstantiationDisable = {
        classCateCodeDis: true, //文件类目不可修改
        fileClassCodeDis: true //文件类型不可修改
    }
    //调用初始化方法
    initFileUpload($$scope, fileInstantiation, fileInstantiationDisable, $certusUtils);

    $certusUtils.ajax("contractProgresss", { "projId": proId }, function (response) {
        var data = response.data;
        var codeList = [];
        for (var i = 0; i < data.length; i++) {
            var ctinfo = data[i].contractInfo;
            var arr = {};
            arr.code = ctinfo.contractNo;
            codeList.push(arr)
        }
        $$scope.data = codeList;
    })
}

$(".toRegu").on('click', function () {
    if (!certusValidateNotnull()) {
        return;
    }
    // fileUpload($$scope,function (res){
    var arr = $("form").serializeArray();
    var data = {};
    for (var i = 0; i < arr.length; i++) {
        data[arr[i].name] = arr[i].value;
    };
    //上传附件
    data.proId = proId;
    $certusUtils.ajax("addAccetpances", { "projId": proId, "param": JSON.stringify(data) }, function (response) {
        layer.msg("添加成功", { "time": 1000 });
        toLoadHtml(101);
    });
    // },null,$certusUtils);
});


// function editAccps(id) {
//     alert(id)
// }

function toBack() {
    toLoadHtml(101);
}